/*
	Subscriber.h - Prototype of a message subscriber
	License: BSD
*/
#pragma once
#ifndef SUBSCRIBER_H_INCLUDED
#define SUBSCRIBER_H_INCLUDED

#include <vector>
#include <queue>

class Message;

#ifndef MUTEX_H_INCLUDED
#include "Mutex.h"
#endif

class Subscriber
{
	std::vector<int>     m_subscription_ids;
	std::queue<Message*> m_message_queue;
	Mutex                m_cs_message_queue;

	void _lock();
	void _unlock();

public:
	Subscriber();
	~Subscriber();

	// subscription functions
	bool is_subscribed( int id ) const;
	void add_subscription( int id );
	void remove_subscription( int id );

	bool     has_messages();
	void     add_message( Message* message );
	Message* get_message( ); // assumed that it removes the message from the queue
	void     clear_messages();
};

#endif // SUBSCRIBER_H_INCLUDED